package entity.lianxi.demo06;

import java.lang.reflect.Method;
import java.util.Scanner;

public class Email {
        public static void main(String[] args) throws Exception {
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入一个合法的 Email 地址：");
            String email = sc.nextLine();

            Class<?> clazz = String.class;
            Method indexOfMethod = clazz.getMethod("indexOf", int.class);
            int atIndex = (int) indexOfMethod.invoke(email, '@');
            Method substringMethod = clazz.getMethod("substring", int.class, int.class);
            String accountName = (String) substringMethod.invoke(email, 0, atIndex);
            System.out.println("Email 的账户名是：" + accountName);


    }
}
